from django.db import models
from human.models import UserModel
from department.models import DoctorModel
from pdata.models import PListModel
from coupon.models import CouponLogModel
# Create your models here.

class QImageModel(models.Model):
    image_path = models.CharField(max_length=128, verbose_name='图片路径')
    question = models.ForeignKey('QuestionModel', on_delete=models.CASCADE,db_constraint=False,
                                 related_name="qimage_question",verbose_name='问题')

    def __str__(self):
        return self.image_path

    class Meta:
        db_table = 'dx_qimage'
        verbose_name = '提问的图片'
        verbose_name_plural = verbose_name

    @property
    def get_image_path(self):
        return 'http://127.0.0.1:8000/media/' + self.image_path



class QuestionModel(models.Model):
    write = models.TextField(verbose_name='提问内容')
    order = models.ForeignKey('OrderModel', on_delete=models.CASCADE,db_constraint=False,
                              related_name="order_question",verbose_name='订单')

    def __str__(self):
        return self.write

    class Meta:
        db_table = 'dx_question'
        verbose_name = '提问'
        verbose_name_plural = verbose_name






class OrderModel(models.Model):
    PAY_STATUS = (
        (0,'未支付'),
        (1,'已支付'),
        (2,'未完成'),
        (3,'已过期'),
        (4,'已退款'),
    )
    OPEN_STATUS = (
        (0,'否'),
        (1,'是'),
    )
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING,db_constraint=False,
                             related_name="order_user",verbose_name='用户')
    doctor = models.ForeignKey(DoctorModel, on_delete=models.DO_NOTHING,db_constraint=False,
                               related_name="order_doctor",verbose_name='医生')
    patient = models.ForeignKey(PListModel, on_delete=models.DO_NOTHING,db_constraint=False,
                                related_name="order_plist",verbose_name='患者')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    pay_time = models.DateTimeField(null=True, blank=True, verbose_name='支付时间')
    pay_status = models.SmallIntegerField(choices=PAY_STATUS, default=0,null=True,blank=True, verbose_name='支付状态')
    order_id = models.CharField(max_length=128,verbose_name='订单号')
    coupon = models.ForeignKey(CouponLogModel, on_delete=models.DO_NOTHING,db_constraint=False,null=True, blank=True,
                               related_name="order_coupon",verbose_name='优惠券')
    price = models.CharField(max_length=10, verbose_name='实际价格')
    pay_price = models.CharField(max_length=10,null=True,blank=True, verbose_name='支付价格')
    open_status = models.SmallIntegerField(choices=OPEN_STATUS,default=0,blank=True,null=True, verbose_name='是否公开')



    def __str__(self):
        return self.order_id

    class Meta:
        db_table = 'dx_order'
        verbose_name = '订单'
        verbose_name_plural = verbose_name






